package com.foreverwin.jzymes.archive.util;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * 异步任务管理器
 * 
 * @author liuhulu
 */
public class AsyncManager
{
    /**
     * 异步操作任务调度线程池
     */
    private ExecutorService executor = Executors.newCachedThreadPool();

    /**
     * 单例模式
     */
    private static AsyncManager me = new AsyncManager();

    public static AsyncManager me()
    {
        return me;
    }

    /**
     * 执行任务
     * 
     * @param 任务task
     */
    public void execute( Runnable task )
    {
        executor.execute( task );
    }

    public Future submit( Runnable task ){
        return executor.submit( task );
    }

    public Future submit( Callable task ){
        return executor.submit( task );
    }
}
